<%@page import="com.wiseMen.platform.support.security.UserUtils"%>
<%@page import="java.util.UUID"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
    String userId = UserUtils.getCurrendUser().getId();
%>
<div class="container-fluid">
	<div class="row">
		<div class="col-md-8">
			<div class="nav-tabs-custom">
	    		<ul class="nav nav-tabs" role="tablist">
		    		<li class="active">
		    			<a href="#tab01_${uuid }" role="tab" data-toggle="tab">
		    			<span class="glyphicon glyphicon-search" aria-hidden="true"></span>知识查询
		    			</a>
		    		</li>
		    		<li>
		    			<a href="#tab02_${uuid }" role="tab" data-toggle="tab">
		    			<span class="glyphicon glyphicon-star" aria-hidden="true"></span>我的收藏
		    			</a>
		    		</li>
		    		<li>
		    			<a href="#tab03_${uuid }" role="tab" data-toggle="tab">
		    			<span class="glyphicon glyphicon-time" aria-hidden="true"></span>浏览历史
		    			</a>
		    		</li>
		    	</ul>
		    	<div class="tab-content">
		    		<div role="tabpanel" class="tab-pane active" id="tab01_${uuid}">
		    			<div class="row" style="margin-top: 10px;">
		    				<div class="col-md-1"></div>
							<div class="col-md-10">
								<form name="kbmsSearchForm" method="post" onsubmit="return false">
									<input type="hidden" name="perSearchText"/>
									<div class="input-group text-right">
						                 <input type="text" id="txt_${uuid}" name="searchText" placeholder="请输入您要搜索的内容" class="form-control input-lg">
						                 <span class="input-group-btn">
						                     <button class="btn btn-default btn-lg" onclick="kbms_searcher(1)" type="button">
												<span class="glyphicon glyphicon-search"></span>&nbsp;搜索
						                     </button>
						                 </span>
					                 </div>
				                  </form>
				            </div>
				            <div class="col-md-1"></div>
			            </div>
			            <div style="width: 99%;margin: 20px auto 5px auto;">
							<ul id="searcherList_${uuid }" class="media-list"></ul>
						</div>
		    	 	</div>
		    	 	<div role="tabpanel" class="tab-pane" id="tab02_${uuid}">
						<div class="box-body">
							<form id="search01_${uuid}" class="form-float" >
		            		</form>
							<table id="grid01_${uuid}"  style="width: 100%"></table>
						</div>
		    	 	</div>
		    	 	<div role="tabpanel" class="tab-pane" id="tab03_${uuid}">
						<table id="grid02_${uuid}"  style="width: 100%"></table>
		    	 	</div>
		    	</div>
	    	</div>
		</div>
		<div class="col-md-4">
			<div class="box box-warning">
				<div class="box-header with-border">
					<h3 class="box-title">留言板</h3>
					<div class="pull-right">
						<a href="javascript:leaveMessageMore();">更多</a>
					</div>
				</div>
				<div class="box-body">
					<form id="LeaveMessageForm_${uuid}">
					<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-top: 5px;">
						<tbody>
							<tr style="height: 60px;">
								<td><textarea name="content" placeholder="请输入留言内容" style="width:100%;height: 80px;"></textarea></td>
							</tr>
							<tr>
								<td class="text-right">
									<div class="radio">
									  <label>
									    <input type="radio" checked='checked' value="1" name="isun">匿名
									  </label>
									  <label>
									    <input type="radio" value="0" name="isun">实名
									  </label>
									</div>
								</td>
							</tr>
							<tr>
								<td class="text-right">
									<button id="submitBtn_${uuid }" type="button" class="btn btn-primary navbar-btn">发表</button>
								</td>
							</tr>
						</tbody>
					</table>
					</form>
				</div>
			</div>
			
			<div class="nav-tabs-custom">
	    		<ul class="nav nav-tabs" role="tablist">
		    		<li class="active">
		    			<a href="#tab201_${uuid }" role="tab" data-toggle="tab">
		    				<span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span>最新知识
		    			</a>
		    		</li>
		    		<li>
		    			<a href="#tab202_${uuid }" role="tab" data-toggle="tab">
		    				<span class="glyphicon glyphicon-asterisk" aria-hidden="true"></span>热点知识
		    			</a>
		    		</li>
		    	</ul>
		    	<div class="tab-content">
		    	 	<div role="tabpanel" class="tab-pane active" id="tab201_${uuid}">
						<table id="grid201_${uuid}"  style="width: 100%"></table>
		    	 	</div>
		    	 	<div role="tabpanel" class="tab-pane" id="tab202_${uuid}">
						<table id="grid202_${uuid}"  style="width: 100%"></table>
		    	 	</div>
		    	</div>
	    	</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(function(){
	
	requirejs(['wiseMen/dataModel/QueryDefTpl'],function(QueryDefTpl){
		var uuid = '${uuid}';
		
		var grid01=new QueryDefTpl({
			code:"KBMS_INFO_COLLECTION",
			searchBarType:"top",
			queryDatas:{USERID:'<%=userId%>'},
			searchDiv:"#search01_"+uuid,//查询定义栏
			toolBarDiv:"#search01_"+uuid+" .searchBtBar",//工具栏定义栏
			gridDiv:"#grid01_"+uuid//grid表格
		});
		
		var grid02=new QueryDefTpl({
			code:"KBMS_INFO_SKIM_RECORD",
			searchBarType:"dialog",
			selectModel:'single',
			queryDatas:{USERID:'<%=userId%>'},
			gridDiv:"#grid02_"+uuid//grid表格
		});
		
		var grid201=new QueryDefTpl({
			code:"KBMS_INF_NEW",
			selectModel:'single',
			pageSize:10,
			gridDiv:"#grid201_"+uuid//grid表格
		});
		
		var grid202=new QueryDefTpl({
			code:"KBMS_INFO_HOTSPOT",
			selectModel:'single',
			pageSize:10,
			gridDiv:"#grid202_"+uuid//grid表格
		});
		
		$( "#txt_${uuid}" ).autocomplete({
	    	source: function(request, response ) {
	            $.ajax({
	                url: ctx + "/KBMS/Keywork/search.do",
	                dataType: "json",
	                data:{
	                	keywork: request.term
	                },
	                success: function( data ) {
	                    response( $.map( data, function( item ) {
	                        return item;
	                    }));
	                }
	            });
	        },
	        minLength:1,
	        delay:1000,
	        select: function( event, ui ) {},
	        change: function( event, ui ) {}
	    });
	    
		$("#submitBtn_${uuid}").click(function(){
			var form = $("#LeaveMessageForm_${uuid}");
			var content = form.find("textarea[name=content]").val();
			var isun = form.find("input[name=isun]").val();
			if($.trim(content)==''){
				webUtils.alert("请填写评论内容！");
				return;
			}
			$.post(ctx+"/PF/leaveMsg/add.do",{
				pid:'-1',
				isun:isun,
				content:content
			},function(data){
				webUtils.alert(data.msg);
				form.find("textarea[name=content]").val("");
			},'json');
		});
		
		$("#txt_${uuid}").bind("focus",function(){
			$('#txt_${uuid}').bind('keyup', function(event) {
				if (event.keyCode == "13") {
					kbms_searcher(1);
				}
			});
		});
		
		$("#txt_${uuid}").bind("blur",function(){
			$('#txt_${uuid}').unbind('keyup');
		});
	});
});
function kbms_searcher(pageNum){
	var searchText = $("form[name='kbmsSearchForm'] input[name='searchText']").val();
	searcherSbumit(pageNum,searchText);
	$("form[name='kbmsSearchForm'] input[name='perSearchText']").val(searchText);
}

function pageSearcher(pageNum){
	var searchText = $("form[name='kbmsSearchForm'] input[name='perSearchText']").val();
	searcherSbumit(pageNum,searchText);
}

function search_perview(id){
	var uuid = '${uuid}';
	webUtils.dialog({
		title:'查看知识详情',
		url:ctx+"/KBMS/issue/perviewInfo.do?isSkim=1&id="+id+"&winId="+uuid,
		onremove:function(){
			webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
		}
	});
}

/**
 * 全文搜索
 */
function searcherSbumit(pageNum,searchText){
	if($.trim(searchText)!=''){
		$.post(ctx+"/KBMS/searcher/search.do",{
			searchText:searchText,
			pageNum:pageNum,
			pageSize:30
		},function(data){
			if(data.success){
				data = data.obj;
				var list = $("#searcherList_${uuid }");
				if(data.dataSize>0){
					list.empty();
					for(var i=0; i<data.data.length; i++){
						var entity = data.data[i];
						var contentStr = entity.contentStr;
						if(contentStr.length>400){
							contentStr = contentStr.substring(0,200);
						}
						list.append(getSearcherListItems().format("<a href='javascript:search_perview(\""+entity.id+"\")'>"+entity.title+"</a>"
								,contentStr,"发布人："+entity.issueUserName,"发布时间："+entity.issueTimeStr));
					}
					if(data.totalPage>0){
						var pagination = "<li><nav class='text-center'><ul class='pagination'><li><a href='javascript:pageSearcher(1)'>&laquo;</a></li>";
						for(var i=1; i<=data.pageRange.length; i++){
							pagination += "<li class='{0}'><a href='javascript:pageSearcher("+i+")'>"+i+"</a></li>";
							if(data.pageNum==i){
								pagination = pagination.format("active");
							}else{
								pagination = pagination.format("");
							}
						}
						pagination += "</li><li><a href='javascript:pageSearcher("+data.totalPage+")'>&raquo;</a></li></ul></nav>";
						list.append(pagination);
					}
				}else{
					list.empty();
					list.append(getSearcherListItems().format("","<div style='color:#ccc;'>没有找到相关数据。</div>",""));
				}
			}else{
				
			}
		},'json');
	}
}

function getSearcherListItems(){
	return "<li class='media'>"+
				"<div class='media-body'>"+
					"<h3 class='media-heading'>{0}</h3>{1}"+
					"<div class='media-bottom help-block'><div class='pull-left'>{2}</div><div class='pull-right'>{3}</div></div>"+
				"</div>"+
		   "</li>";
}

/**
 * 查看更多留言
 */
function leaveMessageMore(){
	var uuid = '${uuid}';
	webUtils.dialog({
		title:'留言板',
		url:ctx+"/PF/leaveMsg/Index.do?winId="+uuid,
		onremove:function(){
			webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
		}
	});
}
</script>